package com.xuxiao.springbootexp03.Service;

import com.xuxiao.springbootexp03.Dao.RegionPropertiesDao;
import com.xuxiao.springbootexp03.Entity.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class RegionPropertiesService {

    @Autowired
    private RegionPropertiesDao dao;

    public List<Region> getByCountry(String country){
        try {
            return dao
                    .getRegionList()
                    .parallelStream()
                    .filter(region -> region.getCountry().equals(country))
                    .collect(Collectors.toUnmodifiableList());
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<Region>();
        }
    }

    public List<Region> getAllRegion(){
        try {
            return dao.getRegionList();
        }catch (Exception e){
            e.printStackTrace();
            return new ArrayList<Region>();
        }
    }

//    public List<Region> getByLatAndLong(String Lat,String Long) throws IOException {
//        return dao
//                .getRegionList()
//                .parallelStream()
//                .filter(region -> region.getLatitude().equals(Lat)&&region.getLongitude().equals(Long))
//                .collect(Collectors.toUnmodifiableList());
//    }
}
